<template>
  <div class="app-container">

    <u-page title="小程序配置">
      <div slot="header">
        <el-button type="primary" @click="updateData">保存</el-button>
      </div>
      <el-form ref="dialogForm" :model="dataForm" :rules="rules" label-width="120px">
        <el-form-item prop="homePic" label="首页图片">
          <u-upload v-model="dataForm.homePic" name="file" tips="首页顶部图片 750*300" />
        </el-form-item>
        <el-form-item prop="xfPic" label="今日消费按钮">
          <u-upload v-model="dataForm.xfPic" name="file" tips="今日消费按钮 尺寸1:1" />
        </el-form-item>
        <el-form-item prop="homePic" label="返券记录按钮">
          <u-upload v-model="dataForm.jlPic" name="file" tips="返券记录按钮 尺寸1:1" />
        </el-form-item>
        <el-form-item prop="broadcast" label="默认广播">
          <el-input v-model="dataForm.defaultBroadcast" type="textarea" placeholder="默认广播" clearable rows="5" />
        </el-form-item>
        <el-form-item prop="broadcast" label="时段广播">
          <el-input v-model="dataForm.broadcast" type="textarea" placeholder="时段广播文案" clearable rows="5" />
        </el-form-item>
        <el-form-item label="广播时段" prop="validityDate">
          <u-date-time-picker v-model="dataForm.validityDate" value-format="yyyy-MM-dd HH:mm:ss" />
        </el-form-item>
      </el-form>
    </u-page>

  </div>
</template>
<script>
export default {
  data() {
    return {
      api: this.$u.api.RebatenewConfig,
      dataForm: {},
      rules: {
      }
    }
  },
  created() {
    this.getLoad()
  },
  methods: {
    // 初始化数据
    getLoad() {
      this.api.config().then(res => {
        this.dataForm = res.data
        this.dataForm.validityDate = [this.dataForm.beginDate, this.dataForm.endDate]
      })
    },
    // 提交编辑数据
    updateData() {
      const { validityDate } = this.dataForm
      if (validityDate) {
        this.dataForm.beginDate = validityDate[0]
        this.dataForm.endDate = validityDate[1]
      }
      const self = this
      this.$confirm('确认更改返券小程序设置', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        self.$refs['dialogForm'].validate((valid) => {
          if (valid) {
            self.api.update(self.dataForm).then(() => {
              self.getLoad()
              self.$u.msg('保存成功')
            })
          }
        })
      }).catch(() => {
      })
    }
  }

}
</script>

